﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width:600px; margin-top: 150px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb clearfix">

      <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>添加账户</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/principals?create-type=COACH" data-validate="true">
      
      <input type="hidden" name="admin" value="false">
      <input type="hidden" name="enterprise" value="true">
      <input type="hidden" name="type" value="SITE">
      
      <div class="modal-body">
        <div class="form-group">
          <label class="control-label col-xs-4">手机号码：</label>
          <div class="col-xs-6 pull-left">
            <input type="text" name="mobile" class="form-control" data-validate="required|mobile">
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-xs-4">微信号：</label>
          <div class="col-xs-6 pull-left">
            <input type="text" name="weixinid" class="form-control" data-validate="required|wechat_number">
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-xs-4">姓名：</label>
          <div class="col-xs-6 pull-left">
            <input type="text" name="name" class="form-control" data-validate="required">
          </div>
        </div>
        
        <div class="form-group">
          <label class="control-label col-xs-4">用户角色：</label>
          <div class="col-xs-6 pull-left">
            <p class="form-control-static">教练</p>
            <input type="hidden" name="authority" value="ROLE_COACH">
          </div>
        </div>
        <c:choose>
          <c:when test="${not empty currentPrincipal.site}">
            <div class="form-group site-select">
              <label class="control-label col-xs-4">店长：</label>
              <div class="col-xs-6 pull-left">
                <p class="form-control-static">${currentPrincipal.name}</p>
                <input type="hidden" name="managerId" value="${currentPrincipal.id}">
              </div>
            </div>
          </c:when>
          <c:otherwise>
            <div class="form-group site-manager-select">
              <label class="control-label col-xs-4">店长：</label>
              <div class="col-xs-6 pull-left">
                <select name="managerId"  class="form-control ignore-validate" data-validate="required">
                  <option></option>  
                  <c:forEach var="relation" items="${persist.managers}">
                      <option value="${relation.key}">${relation.value.manager.name}</option>
                  </c:forEach>
                </select>
              </div>
            </div>
          </c:otherwise>
        </c:choose>
        

      </div>
      
      <div class="modal-footer clearfix">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script>
  $(function() {
    
    $('select[name="managerId"]').select2({
        placeholder : '请选择店长',
        minimumResultsForSearch : -1,
        allowClear : true
    });
    
  })
</script>